fix(loader): close model task JSON file and read it as UTF-8#1422
Open
genisis0x wants to merge 1 commit into
Open
fix(loader): close model task JSON file and read it as UTF-8#1422genisis0x wants to merge 1 commit into
genisis0x wants to merge 1 commit into
Conversation
ModelTaskLoaderJson.load read the model JSON via json.load(open(...)), which both leaked the file handle (never closed) and used the platform default encoding (cp1252/gbk on Windows). Model JSON can carry non-ASCII content and JSON is UTF-8 by default per RFC 8259 section 8.1, so the load could raise UnicodeDecodeError on non-UTF-8 locales. Use a context manager with encoding pinned to utf-8.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
ModelTaskLoaderJson.load(rdagent/components/loader/task_loader.py) read the model JSON viajson.load(open(self.json_uri, "r")). That has two problems:encoding, so the read falls back to the platform default —cp1252/gbkon Windows.Model definition JSON can carry non-ASCII content, and JSON is UTF-8 by default per RFC 8259 §8.1, so on a non-UTF-8 locale the load raises
UnicodeDecodeError.Change
Wrap the read in a
withcontext manager and pinencoding="utf-8". Closes the handle deterministically and makes the read locale-independent. No behavior change on UTF-8 locales.Testing
json.loadof a model JSON containing non-ASCII content now succeeds independent oflocale.getpreferredencoding(); the file handle is released on block exit.📚 Documentation preview 📚: https://RDAgent--1422.org.readthedocs.build/en/1422/